/*     */ package com.ourgame.tankgame.screen;
/*     */
/*     */ import de.lessvoid.nifty.Nifty;
/*     */ import de.lessvoid.nifty.effects.EffectImpl;
/*     */ import de.lessvoid.nifty.effects.EffectProperties;
/*     */ import de.lessvoid.nifty.effects.Falloff;
/*     */ import de.lessvoid.nifty.elements.Element;
/*     */ import de.lessvoid.nifty.render.NiftyImage;
/*     */ import de.lessvoid.nifty.render.NiftyRenderEngine;
/*     */ import de.lessvoid.nifty.tools.TimeProvider;
import gameutil.Globals;
/*     */ import java.util.Random;
/*     */
/*     */ public class BubblesEffect
        /*     */ implements EffectImpl /*     */ {
    /*     */ private Bubble[] bubbles;
    /*     */ private int screenWidth;
    /*     */ private int screenHeight;
    /*     */ private Random random;
    /*     */ private TimeProvider timeProvider;
    /*     */ private NiftyImage niftyImage1;
    /*     */ private NiftyImage niftyImage2;
        private NiftyImage logoImage1;
        private NiftyImage logoImage2;
    /*     */
    /*     */ public BubblesEffect() /*     */ {
        /*  16 */ this.bubbles = new Bubble[32];
        /*     */
        /*  19 */ this.random = new Random();
        /*  20 */ this.timeProvider = new TimeProvider();
        /*     */    }
    /*     */
    /*     */ public void activate(Nifty nifty, Element element, EffectProperties parameter) /*     */ {
        /*  25 */ this.niftyImage1 = nifty.getRenderEngine().createImage(Globals.bubblesEffectpic1, true);
        /*  26 */ this.niftyImage2 = nifty.getRenderEngine().createImage(Globals.bubblesEffectpic2, true);
                  this.logoImage1 = nifty.getRenderEngine().createImage(Globals.logoEffectpic1, true);
                  this.logoImage2 = nifty.getRenderEngine().createImage(Globals.logoEffectpic2, true);
        /*  27 */ this.screenWidth = nifty.getCurrentScreen().getRootElement().getWidth();
        /*  28 */ this.screenHeight = nifty.getCurrentScreen().getRootElement().getHeight();
        /*  29 */ for (int i = 0; i < this.bubbles.length; i++) /*  30 */ {
            this.bubbles[i] = new Bubble(this.timeProvider.getMsTime());
        }
        /*     */    }
    /*     */
    /*     */ public void deactivate() /*     */ {
//        /*  35 */ this.niftyImage1.dispose();
//        /*  36 */ this.niftyImage2.dispose();
                    this.logoImage1.dispose();
                    this.logoImage2.dispose();
        /*     */    }
    /*     */
    /*     */ public void execute(Element element, float effectTime, Falloff falloff, NiftyRenderEngine r) {
        /*  40 */ for (Bubble bubble : this.bubbles) {
            /*  41 */ bubble.update(this.timeProvider.getMsTime());
            /*  42 */ bubble.render(r);
        }
    }
    /*     */ private class Bubble {

        private static final int Y_MIN_1 = 100;
        /*     */ private static final int Y_MIN_2 = 140;
        /*     */ private static final int Y_MAX_1 = 628;
        /*     */ private static final int Y_MAX_2 = 668;
        /*     */ private int x;
        /*     */ private int initialX;
        /*     */ private int y;
        /*     */ private int sizeX;
        /*     */ private int sizeY;
        /*     */ private long speed;
        /*  57 */ private boolean enabled = true;
        /*     */ private long startTime;
        /*     */ private int speedX;
        /*     */ private int dir;
        /*     */ private int timeX;
        /*     */ private int image;
        /*     */
        /*  65 */ public Bubble(long startTime) {
            initPosition(startTime);
            /*  66 */ this.y = BubblesEffect.this.screenHeight;
            /*  67 */ this.speed = getNewSpeed();
            /*  68 */ this.startTime = (startTime + BubblesEffect.this.random.nextInt((int) this.speed));
        }
        /*     */
        /*     */ private int getNewSpeed() /*     */ {
            /*  72 */ return BubblesEffect.this.random.nextInt(5000) + 8000;
            /*     */        }
        /*     */
        /*     */ private void initPosition(long currentTime) {
            /*  76 */ this.initialX = (this.x = BubblesEffect.this.random.nextInt(BubblesEffect.this.screenWidth));
            /*  77 */ this.speed = getNewSpeed();
            /*  78 */ initWind();
            /*  79 */ this.startTime = currentTime;
            /*  80 */ this.image = BubblesEffect.this.random.nextInt(2);
            /*  81 */ if (this.image == 0) {
                /*  82 */ this.sizeX = 64;
                /*  83 */ this.sizeY = 64;
                /*     */            } else {
                /*  85 */ this.sizeX = 32;
                /*  86 */ this.sizeY = 32;
                /*     */            }
            /*  88 */ this.y = BubblesEffect.this.screenHeight;
            /*     */        }
        /*     */
        /*     */ private void initWind() {
            /*  92 */ this.dir = (BubblesEffect.this.random.nextInt(2) * -1);
            /*  93 */ this.speedX = (BubblesEffect.this.random.nextInt(150) + 150);
            /*  94 */ this.timeX = (BubblesEffect.this.random.nextInt(5000) + 2500);
            /*     */        }
        /*     */
        /*     */ public void update(long currentTime) {
            /*  98 */ long time = currentTime - this.startTime;
            /*  99 */ float t = getSinusValue(currentTime);
            /* 100 */ this.x = (int) (t * this.speedX * this.dir + this.initialX);
            /*     */
            /* 102 */ float value = (float) (this.speed - time) / (float) this.speed;
            /* 103 */ this.y = (int) (BubblesEffect.this.screenHeight * value);
            /* 104 */ if (this.y < 100) {
                /* 105 */ initPosition(currentTime);
                /* 106 */ this.enabled = true;
                /*     */            }
            /*     */        }
        /*     */
        /*     */ public void render(NiftyRenderEngine r) {
            /* 111 */ if (this.enabled) {
                /* 112 */ if (this.y < 100) /* 113 */ {
                    return;
                }
                /* 114 */ if (this.y < 140) {
                    /* 115 */ r.setColorAlpha(1.0F - (140.0F - this.y) / 40.0F);
                    /* 116 */                } else if ((this.y > 628) && (this.y < 668)) {
                    /* 117 */ float max = 628.0F;
                    /* 118 */ r.setColorAlpha(1.0F - (this.y - max) / 40.0F);
                } else {
                    /* 119 */ if (this.y >= 668) {
                        /* 120 */ return;
                        /*     */                    }
                    /* 122 */ r.setColorAlpha(1.0F);
                    /*     */                }
                /* 124 */ if (this.image == 0) /* 125 */ {
//                    r.renderImage(BubblesEffect.this.niftyImage1, this.x, this.y, this.sizeX, this.sizeY);
                    r.renderImage(BubblesEffect.this.logoImage1, this.x, this.y, this.sizeX, this.sizeY);
                } /*     */ else /* 127 */ {
//                    r.renderImage(BubblesEffect.this.niftyImage2, this.x, this.y, this.sizeX, this.sizeY);
                    r.renderImage(BubblesEffect.this.logoImage2, this.x, this.y, this.sizeX, this.sizeY);
                }
                /*     */            }
            /*     */        }
        /*     */
        /*     */ private float getSinusValue(long x) /*     */ {
            /* 134 */ return (float) ((Math.sin(3.141592653589793D * x / this.timeX) + 1.0D) / 2.0D);
            /*     */        }
        /*     */    }
    /*     */ }
